﻿<UserControl x:Class="SLAdmin.UserControls.EditStudy"             
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:extended="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:liquid="clr-namespace:Liquid;assembly=Liquid"
    xmlns:images="clr-namespace:SLAdmin.Images"    
    xmlns:extensions="clr-namespace:SLExtensions.Controls;assembly=SLExtensions.Controls"    
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:converters="clr-namespace:Common.Converters;assembly=Common"             
    >
    <UserControl.Resources>
        <converters:ImageUriConverter x:Name="myImageUriConverter"/>
        <converters:PathFileNameConverter x:Name="myPathFileNameConverter"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Style="{StaticResource MainDockBackground2}">        
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="100"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="50" MinHeight="50"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="130" />
                    <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Source="icons/Study_128.png" />
                <TextBox Grid.Column="1" Text="{Binding StudyName, Mode=TwoWay}" Style="{StaticResource TextBoxMainHeadline}"/>
            </Grid>
            <Border Grid.Row="2" Style="{StaticResource BorderBottomPanel}">
                <Button x:Name="btnSave" Margin="10,0,0,0"  
                        Style="{StaticResource Button_Save}"                    
                        Click="btnSave_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="icons/filesave-32.png"/>
                        <TextBlock Margin="5,0,0,0"
                               VerticalAlignment="Center" 
                               Text="Save"/> 
                            </StackPanel>
                </Button>
            </Border>
            <extended:TabControl x:Name="StudyTabs" Grid.Row="1"
                                 Background="White" SelectionChanged="StudyTabs_SelectionChanged">
                <extended:TabItem Padding="5">
                    <extended:TabItem.Header >
                        <StackPanel Margin="5" Orientation="Horizontal">
                            <Image Source="icons/configure_32.png"/>
                            <TextBlock Text="General"
                                   Style="{StaticResource TextBlockTabName}"
                                   />
                    </StackPanel>
                    </extended:TabItem.Header>
                    <extensions:DockPanel Style="{StaticResource DockMainTabPage}">
                        <ScrollViewer Style="{StaticResource ScrollViewerTabWindow}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="200" />
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="40"/>
                                    <RowDefinition Height="50"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="150"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" Style="{StaticResource TextBlockItemLabel}"                                    
                                   Grid.Row="0" Text="Study Description"/>
                    <extended:GridSplitter VerticalAlignment="Stretch" Grid.Column="0"/>
                    <TextBox Grid.Column="1" Grid.Row="0" Style="{StaticResource TextBoxLargeInput}" 
                             Text="{Binding StudyDescription, Mode=TwoWay}"/>
                    <TextBlock Grid.Column="0" Style="{StaticResource TextBlockItemLabel}" 
                               Grid.Row="1" Text="Maximum Participants"/>                    
                    <TextBox Grid.Column="1" 
                               Grid.Row="1" Style="{StaticResource TextBoxSingleLineInputShort}"                               
                               Text="{Binding MaxParticipants, Mode=TwoWay}"
                               />
                    <TextBlock Grid.Column="0" Style="{StaticResource TextBlockItemLabel}"  
                               Grid.Row="2" Text="Open Date"/>                    
                    <extended:DatePicker Grid.Column="1" Grid.Row="2" 
                                         Style="{StaticResource DatePickerInputStyle}"
                                         SelectedDate="{Binding OpenDate, Mode=TwoWay}"/>                         
                     <TextBlock Grid.Column="0" Style="{StaticResource TextBlockItemLabel}"  
                               Grid.Row="3" Text="Survey URL"/>  
                               <StackPanel Grid.Column="1" 
                               Grid.Row="3" Orientation="Horizontal">
                                   <TextBox Style="{StaticResource TextBoxSingleLineInputLong}"                               
                                       Text="{Binding StudyURL, Mode=TwoWay}"
                                       />
                                    <Button x:Name="btnRun" Margin="10,0,0,0" 
                                                Style="{StaticResource Button_Save}"                    
                                                Click="btnRun_Click">
                                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                                <Image Source="icons/agt_runit-32.png"/>
                                                <TextBlock Margin="5,0,0,0"
                                                       VerticalAlignment="Center" 
                                                       Text="Run"/> 
                                                    </StackPanel>
                                        </Button>
                               </StackPanel>
                      
                                </Grid>
                        </ScrollViewer>
                    </extensions:DockPanel>
                </extended:TabItem>
                <extended:TabItem VerticalAlignment="Stretch">
                    <extended:TabItem.Header>
                        <StackPanel Margin="5" Orientation="Horizontal">
                            <Image Source="icons/Condition.png"/>
                            <TextBlock Text="Conditions" Style="{StaticResource TextBlockTabName}"
                                   />
                    </StackPanel>
                    </extended:TabItem.Header>
                    <extensions:DockPanel Style="{StaticResource DockMainTabPage}">
                        <Border extensions:DockPanel.Dock="Bottom" Style="{StaticResource BorderTabBottomPanel}">
                            <Button x:Name="btnNewCondition" 
                                    Style="{StaticResource ButtonMedium}"
                                    Click="btnNewCondition_Click">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                    <Image Source="icons/Condition_15.png"/>
                                    <TextBlock Text="New Condition" 
                                           Margin="5,0,0,0" 
                                           VerticalAlignment="Center" />    
                                </StackPanel>
                            </Button>
                        </Border>
                        <ScrollViewer Style="{StaticResource ScrollViewerTabWindow}">
                            <StackPanel Orientation="Vertical">
                                <data:DataGrid x:Name="ConditionGrid"
                                               AutoGenerateColumns="False"
                                                
                                                HeadersVisibility="Column"
                                                RowBackground="White"
                                                AlternatingRowBackground="LightGray"
                                                CanUserResizeColumns="False"                                                
                                                RowHeight="45">
                                    <data:DataGrid.Columns>
                                        <data:DataGridTemplateColumn Width="30">
                                            <data:DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Source="icons/Condition.png" Margin="3" />
                                                </DataTemplate>
                                            </data:DataGridTemplateColumn.CellTemplate>
                                        </data:DataGridTemplateColumn>
                                        <data:DataGridTextColumn MinWidth="200" Width="Auto" 
                                                                 Binding="{Binding ConditionName, Mode=TwoWay}"/>
                                        <data:DataGridTemplateColumn Width="50" MinWidth="50">
                                            <data:DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Button Margin="3" Click="btnConditionDelete_Click"
                                                        x:Name="btnConditionDelete">
                                                        <images:DeleteIcon/>
                                                    </Button>
                                                </DataTemplate>
                                            </data:DataGridTemplateColumn.CellTemplate>
                                        </data:DataGridTemplateColumn>
                                    </data:DataGrid.Columns>                                    
                                </data:DataGrid>                                
                            </StackPanel>
                        </ScrollViewer>
                    </extensions:DockPanel>
                    
                </extended:TabItem>
                <extended:TabItem>
                    <extended:TabItem.Header>
                        <StackPanel Margin="5" Orientation="Horizontal">
                            <Image Source="icons/Column-Chart-32x32.png"/>
                            <TextBlock Text="Waves" 
                                   Style="{StaticResource TextBlockTabName}"
                                   />
                    </StackPanel>
                    </extended:TabItem.Header>
                    <extensions:DockPanel Style="{StaticResource DockMainTabPage}">
                        <Border extensions:DockPanel.Dock="Bottom" Style="{StaticResource BorderTabBottomPanel}">
                            <Button x:Name="btnNewWave" Click="btnNewWave_Click"  Style="{StaticResource ButtonMedium}">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                    <Image Source="icons/Column-Chart-32x32.png"/>
                                    <TextBlock Text="New Wave" 
                                           Margin="5,0,0,0" 
                                           VerticalAlignment="Center" />    
                            </StackPanel>
                            </Button>
                        </Border>
                        <ScrollViewer Style="{StaticResource ScrollViewerTabWindow}">
                            <StackPanel Orientation="Vertical">
                                <data:DataGrid x:Name="StudyWaveGrid"
                                               AutoGenerateColumns="False"
                                                
                                                HeadersVisibility="Column"
                                                RowBackground="White"
                                                AlternatingRowBackground="LightGray"
                                                CanUserResizeColumns="False"                                                
                                                RowHeight="45">
                                    <data:DataGrid.Columns>
                                        <data:DataGridTemplateColumn Width="34">
                                            <data:DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Source="icons/Column-Chart-32x32.png" Margin="3" />
                                                </DataTemplate>
                                            </data:DataGridTemplateColumn.CellTemplate>
                                        </data:DataGridTemplateColumn>
                                        <data:DataGridTextColumn MinWidth="200" Width="Auto" 
                                                                 Binding="{Binding StudyWaveName, Mode=TwoWay}"/>
                                        <data:DataGridTextColumn Width="Auto"  Header="Day Start Offset"
                                                                 Binding="{Binding DayStartOffset, Mode=TwoWay}"/>
                                        <data:DataGridTextColumn Width="Auto" Header="Day End Offset"
                                                                 Binding="{Binding DayEndOffset, Mode=TwoWay}"/>
                                        <data:DataGridCheckBoxColumn Width="Auto" Header="Notify User?"
                                                                     Binding="{Binding isUserNotifiedbyEmail, Mode=TwoWay}"/>
                                        <data:DataGridTemplateColumn Width="50" MinWidth="50">
                                            <data:DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Button Margin="3" Click="btnStudyWaveDelete_Click"
                                                        x:Name="btnStudyWaveDelete">
                                                        <images:DeleteIcon/>
                                                    </Button>
                                                </DataTemplate>
                                            </data:DataGridTemplateColumn.CellTemplate>
                                        </data:DataGridTemplateColumn>
                                    </data:DataGrid.Columns>
                                </data:DataGrid>
                            </StackPanel>
                        </ScrollViewer>
                    </extensions:DockPanel>                    
                </extended:TabItem>
                <extended:TabItem>
                    <extended:TabItem.Header>
                        <StackPanel Margin="5" Orientation="Horizontal">
                            <Image Source="icons/group_32.png"/>
                            <TextBlock Text="Claims" 
                                   Style="{StaticResource TextBlockTabName}"
                                   />
                    </StackPanel>
                    </extended:TabItem.Header>
                    <extensions:DockPanel Style="{StaticResource DockMainTabPage}">
                        <ScrollViewer Style="{StaticResource ScrollViewerTabWindow}">
                            <StackPanel Orientation="Horizontal">
                                <ListBox x:Name="ClaimsNotAdded" Margin="10" Width="300" 
                                         DisplayMemberPath="ClaimName" 
                                         DataContext="{Binding}"
                                         ItemsSource="{Binding}">                                    
                                </ListBox>
                                <StackPanel Orientation="Vertical">
                                    <Button Margin="0,30,0,10" x:Name="btnAddClaim" 
                                            Click="btnAddClaim_Click" Content="==>"/>
                                    <Button Margin="0,10,0,0" x:Name="btnRemoveClaim" 
                                            Click="btnRemoveClaim_Click" Content="&lt;=="/>
                                </StackPanel>
                                <ListBox x:Name="ClaimsAdded" Margin="10" Width="300"
                                         DisplayMemberPath="ClaimName" 
                                         DataContext="{Binding}"
                                         ItemsSource="{Binding}">
                                </ListBox>
                            </StackPanel>
                        </ScrollViewer>
                    </extensions:DockPanel>
                </extended:TabItem>
                <extended:TabItem x:Name="tabParticipant" >
                    <extended:TabItem.Header>
                        <StackPanel Margin="5" Orientation="Horizontal">
                            <Image Source="icons/participant2_32.png"/>
                            <TextBlock Text="Participants" Style="{StaticResource TextBlockTabName}"/>
                    </StackPanel>
                    </extended:TabItem.Header>
                    <extensions:DockPanel Style="{StaticResource DockMainTabPage}">
                        <Border extensions:DockPanel.Dock="Bottom" Style="{StaticResource BorderTabBottomPanel}">
                            <StackPanel Orientation="Horizontal">
                                <Button x:Name="btnDeleteAll" Click="btnDeleteAll_Click" Style="{StaticResource ButtonMedium}">
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                        <images:DeleteIcon/>
                                        <TextBlock Text="Delete All Data" 
                                               Margin="5,0,0,0" 
                                               VerticalAlignment="Center" />    
                                    </StackPanel>
                                </Button>
                                <Button x:Name="btnExportToExcel" Click="btnExportToExcel_Click" 
                                        Margin="10,0,0,0"
                                        Style="{StaticResource ButtonMedium}">
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                        <Image Source="icons/Excel-32.png"/>
                                        <TextBlock Text="Export to Excel" 
                                               Margin="5,0,0,0" 
                                               VerticalAlignment="Center" />    
                                    </StackPanel>
                                </Button>
                            </StackPanel>
                        </Border>
                        <ScrollViewer Style="{StaticResource ScrollViewerTabWindow}">
                            <!--<ItemsControl x:Name="ParticpantGrid">
                                <ItemsControl.Template>
                                    <ControlTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <Image Source="icons/participant2_32.png"/>
                                            <TextBlock Text="{Binding EmailAddress}"/>
                                        </StackPanel>
                                    </ControlTemplate>
                                </ItemsControl.Template>
                            </ItemsControl>-->
                            <data:DataGrid x:Name="ParticpantGrid"
                                               AutoGenerateColumns="False"
                                                
                                                HeadersVisibility="Column"
                                                RowBackground="White"
                                                AlternatingRowBackground="LightGray"
                                                CanUserResizeColumns="False"                                                
                                                RowHeight="45">
                                
                                <data:DataGrid.Columns>
                                    <data:DataGridTemplateColumn Width="34">
                                        <data:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Image Source="icons/participant2_32.png" Margin="3" />
                                            </DataTemplate>
                                        </data:DataGridTemplateColumn.CellTemplate>
                                    </data:DataGridTemplateColumn>
                                    <data:DataGridTextColumn MinWidth="25" Width="Auto" 
                                                                 Binding="{Binding ConditionName}"/>
                                    <data:DataGridTextColumn Width="Auto"  Header="Id"
                                                                 Binding="{Binding IndividualId}"/>
                                    <data:DataGridTextColumn MinWidth="200" Width="Auto" 
                                                                 Binding="{Binding EmailAddress}"/>                                    
                                    <data:DataGridTextColumn MinWidth="25" Width="Auto" 
                                                                 Binding="{Binding DateStart}"/>
                                    <data:DataGridTemplateColumn Width="50" MinWidth="50">
                                        <data:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Margin="3" Click="btnDeleteIndividualResult_Click"
                                                        x:Name="btnDeleteIndividualResult">
                                                    <images:DeleteIcon/>
                                                </Button>
                                            </DataTemplate>
                                        </data:DataGridTemplateColumn.CellTemplate>
                                    </data:DataGridTemplateColumn>                                    
                                </data:DataGrid.Columns>
                            </data:DataGrid>                            
                        </ScrollViewer>
                    </extensions:DockPanel>    
                </extended:TabItem>
                <extended:TabItem x:Name="tabResources" >
                    <extended:TabItem.Header>
                        <StackPanel Margin="5" Orientation="Horizontal">
                            <Image Source="icons/pictures_32.png"/>
                            <TextBlock Text="Resources" Style="{StaticResource TextBlockTabName}"/>
                    </StackPanel>
                    </extended:TabItem.Header>
                    <extensions:DockPanel Style="{StaticResource DockMainTabPage}">
                        <Border extensions:DockPanel.Dock="Bottom" Style="{StaticResource BorderTabBottomPanel}">
                            <StackPanel Orientation="Horizontal">
                                <Button x:Name="btnUploadFile" Click="btnUploadFile_Click" Style="{StaticResource ButtonMedium}">
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                        <Image Source="icons/up-32.png"/>
                                        <TextBlock Text="Upload File" 
                                               Margin="5,0,0,0" 
                                               VerticalAlignment="Center" />    
                                    </StackPanel>
                                </Button>
                            </StackPanel>
                        </Border>
                        <ScrollViewer Style="{StaticResource ScrollViewerTabWindow}">                            
                            <data:DataGrid x:Name="ResourcesGrid"
                                               AutoGenerateColumns="False"
                                                
                                                HeadersVisibility="Column"
                                                RowBackground="White"
                                                AlternatingRowBackground="LightGray"
                                                CanUserResizeColumns="False"                                                
                                                RowHeight="120">
                                <data:DataGrid.Columns>                                    
                                    <data:DataGridTemplateColumn Width="200">
                                        <data:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Vertical">
                                                <Image Height="100" Source="{Binding '', Converter={StaticResource myImageUriConverter}}"/>
                                                <TextBlock Margin="0,5,0,0" HorizontalAlignment="Center" Text="{Binding '',Converter={StaticResource myPathFileNameConverter}}"/>
                                                </StackPanel>
                                            </DataTemplate>
                                        </data:DataGridTemplateColumn.CellTemplate>
                                    </data:DataGridTemplateColumn>
                                    <data:DataGridTemplateColumn Width="50" MinWidth="50">
                                        <data:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Margin="3" Click="btnDeleteResource_Click" 
                                                        VerticalAlignment="Center"
                                                        x:Name="btnDeleteResource" Height="45">
                                                    <images:DeleteIcon/>
                                                </Button>
                                            </DataTemplate>
                                        </data:DataGridTemplateColumn.CellTemplate>
                                    </data:DataGridTemplateColumn>
                                </data:DataGrid.Columns>
                            </data:DataGrid>
                        </ScrollViewer>
                    </extensions:DockPanel>
                </extended:TabItem>
            </extended:TabControl>

        </Grid>
        
    </Grid>
</UserControl>
